export default {
  props: {

  },
  data () {
    return {
      isFirst: 1, // 大于 1 都不是首次执行
      orgCodeList: [], // 公司部门
      salesAuthority: [], // 跟进客服
      platformDataList: [], // 平台
      shopDataList: [], // 店铺
      approverList: [], // 审核人
      dictionaries: { // 字典数据
        sale_status: [], // 状态
        after_sale_status: [], // 售后订单状态
        goods_type: [], // 商品类型
        order_pay_type: [], // 支付方式
        order_main_status: [], // 订单状态
        order_main_type: [], // 订单类型
        after_sale_reason: [], // 退款原因
        order_status_logistics: [], // 物流订单状态
        order_main_subset_status: [], // 订单子状态
        process_task_status: [], // 审核状态
        courier_company: [], // 物流公司编号
        order_main_close_reason: [],
        customer_intention: [], // 关闭原因
        process_func: [], // 下单-是否必审核
        after_sale_subset_status: [], // 售后步骤
        after_type: [], // 售后类型
        logistics_exception_reason: [], // 物流状态
        order_generate_type: [] // 生成订单方式
		
      },
      parArray: [], // 按钮权限
      dialog: { visible: false, title: '编辑', type: '', row: {}, batch: false }
    }
  },
  computed: {

  },
  created () {
    // const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
    // this.searchForm.orgCode = userInfo.orgCode
    // console.log(this.searchForm.orgCode)
    // 获取字典值
    for (const type in this.dictionaries) { this.getDictionaries(type) }
    // this.getButtonTreeDto()
  },
  methods: {
    // 获取字典数据
    getDictionaries (type) {
      if (type && this.dictionaries[type].length > 0) { return }
      const params = { groupId: type }
      this.$api.dictionaries(params).then((res) => {
        this.dictionaries[type] = res.data
      }).catch((err) => {
        console.log(err)
      })
    },
    // 设置 搜索 筛选 字典 值
    setSearchDictionaries (str, keyVal) {
      // debugger
      const dictionaries = this.dictionaries
      const payIndex = this.searchFormConfig.formconfig.itemList.findIndex(e => { return e.label === str })
      for (const key in dictionaries) {
        if (key === keyVal) {
          dictionaries[key].forEach(item => {
            item.label = item.dictName
            item.value = item.dictId
          })
          this.searchFormConfig.formconfig.itemList[payIndex].option = dictionaries[key]
          break
        }
      }
    },
    getButtonTreeDto (menuCodeStr) {
      // 获取权限设定
      this.limits = JSON.parse(sessionStorage.getItem('limit'))
      const params = this.limits.buttonTreeDto.filter((item) => item.menuCode === menuCodeStr)
      params[0].buttonList.forEach((item) => { this.parArray.push(item.code) })
      // console.log(this.parArray)
    },
    // 显示  dialog
    showDialog (title, width, type, data, batch) {
      this.setCloseOrder = '' // 物流订单待发货关闭订单理由参数
      console.log(title, width, type, data, batch)
      this.dialog = { visible: false, title: '编辑', type: '', row: {}, batch: false }
      if (batch && data.length === 0) {
        this.closeDialog()
        this.$message({
          type: 'warning',
          message: '请选择数据操作!'
        })
        return
      }
      this.dialog.title = title
      this.dialog.type = type
      // if (!batch) { this.dialog.row = data }
      this.dialog.row = data
      this.dialog.visible = true
      this.dialog.width = width
      this.dialog.batch = batch // 是否批量
      console.log(this.dialog)
    },
    // 关闭  dialog
    closeDialog (title, width, type, row) {
      // this.dialog = { visible: false, title: '编辑', type: '', row: {}}
      this.dialog.visible = false
    },
    actionDialog () {
      console.log('actionDialog')
      const dialog = this.dialog
      // 修改售后物流单号
      if (dialog.type === 'modifyOrderNo' || dialog.type === 'modifyOrderNoOne' || dialog.type === 'modifyOrderNoTwo' || dialog.type === 'modifyOrderNoOneTui' || dialog.type === 'exchangeGoods') {
        this.$refs.modifyOrderNo.submit()
      }
      // 修改客服物流单号 批量审核
      if (dialog.type === 'shenhe' || dialog.type === 'audit') { this.$refs.shenhe.submit() }
      if (dialog.type === 'shenheList') { this.$refs.shenheList.auditSubmitList() }

      // 站外订单物流透视
      if (dialog.type === 'transparent') { this.$refs.transparent.submitUpload() }
      // 物流订单发货前修改物流单号
      if (dialog.type === 'editWuliu') { this.$refs.editWuliu.submitWuliu() }
      // if (dialog.type === 'modifyOrderNoOne') { this.$refs.modifyOrderNoOne.submitWuliu() }
      if (dialog.type === 'shenheStep') { this.closeDialog() }
      // 物流订单待发货状态操作发货按钮
      if (dialog.type === 'shipments') { this.$refs.shipments.submitWuliu() }
      // 售后订单审核
      if (dialog.type === 'afterSaleShenhe') { this.$refs.afterSaleShenhe.afterSalesubmit() }
      // this.dialog.visible = false
    },
    // 重置表单
    resetForm (formName) { this.$refs[formName].resetFields() },
    // 公司部门
    getOrgTreeList (params) {
      // orgProcessOrgList
      const paramsVersion = { 'request': { 'orgName': '', 'orgType': '' }, 'version': '' }
      this.$api.orgTreeList(paramsVersion).then((res) => {
        this.orgCodeList = res.data

        // id 为 1 的超级管理员不做默认
        const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
        if (userInfo && userInfo.id !== 1) {
          /*
          if (res.data[0].children) {
            // const orgCode = JSON.parse(sessionStorage.getItem('orgCode'))
            // this.searchForm.orgCode = userInfo.orgCode
            this.searchForm.orgCode = [...userInfo.orgCodes]
          } else {
            this.searchForm.orgCode.push(userInfo.orgCode)
          }
          */
          // this.searchForm.orgCode.push(userInfo.orgCode)
          this.searchForm.orgCode = userInfo.orgCode
          console.log(this.searchForm.orgCode)
          if (this.isFirst > 2) {
            this.fetchData('search')
          }
        }
        this.isFirst++
      }).catch((err) => {
        console.log(err)
      })
    },
    // 跟进客服
    getSalesAuthority (params) {
      this.$api.salesAuthority(params).then((res) => {
        this.salesAuthority = res.data
        const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
        // id 为 1 的超级管理员不做默认
        if (userInfo && userInfo.id !== 1) {
          if (this.searchForm && this.searchForm.applierId) {
            this.searchForm.applierId = userInfo.id
          }
          if (this.isFirst > 2) {
            this.fetchData('search')
          }
        }
        this.isFirst++
      }).catch((err) => {
        console.log(err)
      })
    },
    // 平台
    getPlatformDataList (params) {
      this.$api.platformDataList(params).then((res) => {
        this.platformDataList = res.data
      }).catch((err) => {
        console.log(err)
      })
    },
    // // 审核人
    // getApproverList (params) {
    //   this.$api.approverList(params).then((res) => {
    //     this.approverList = res.data
    //   }).catch((err) => {
    //     console.log(err)
    //   })
    // },
    // 店铺
    getShopDataList (params) {
      this.$api.shopDataList(params).then((res) => {
        this.shopDataList = res.data
      }).catch((err) => {
        console.log(err)
      })
    },
    // 页面跳转
    toOtherPages (name, parameter, type) {
      console.log(name, parameter, type)
      let query = { id: parameter, type }
      if (type === 'category') { query = { category: parameter, type } }
      if (type === 'modify_order') { query = { id: parameter.orderId, orderId: parameter.orderId, orderNo: parameter.orderNo, awaitSubmit: type } }
      if (type === 'orderDetails') { query = { id: parameter.orderId, orderId: parameter.orderId, orderNo: parameter.orderNo, type } }
      if (type === 'logistics') { query = { id: parameter.orderId, orderNo: parameter.orderNo, logistics: 'logistics1' } } // 物流
      if (type === 'afterSaleRecordList') { query = { orderNo: parameter.orderNo } }
      if (type === 'examination') { query = { id: parameter.id, orderNo: parameter.orderNo, approveStatus: parameter.approveStatus ? parameter.approveStatus : 1, audit: 'audit' } }// 审核
      this.$router.push({ name, query })
    }
  }
}
